Used to hold the contents of an email message and its enclosures, if any.
Example
The following example sets the values of the From Address, Subject, Body, and Headers from the values of the Text properties of EditFields in a window. The EditFields named fromAddressfld, subjectFld, bodyFld, and htmlFld contain this information:
Dim file as EmailAttachment
Dim i as Integer
Dim s as String
// set up the socket--Socket1 is an SPTPSocket
socket1.address = serverFld.text
socket1.port = 25
if authenticateBox.value = True then
socket1.username = usernameFld.text
socket1.password = passwordFld.text
else
socket1.username = ""
end
Dim mail as = New EmailMessage
mail.fromAddress=fromAddressFld.text
mail.subject=subjectFld.text
mail.bodyPlainText = bodyFld.text
mail.bodyHTML = htmlFld.text
mail.headers.appendHeader "X-Mailer","REALbasic SMTP Demo"
// add recipients
s = replaceAll(toAddressFld.text,",", Chr(13))
s = ReplaceAll(s, Chr(13)+ Chr(10), Chr(13))
for i = 1 to CountFields(s, Chr(13))
mail.addRecipient Trim( NthField(s, Chr(13),i))
next
// add cc recipients
s = ReplaceAll(ccAddressFld.text,",", Chr(13))
s = ReplaceAll(s, Chr(13)+ Chr(10), Chr(13))
for i = 1 to CountFields(s, Chr(13))
mail.addCCRecipient Trim( NthField(s, Chr(13),i))
next
// add attachments
if fileFld.text <> "" then
file = New EmailAttachment
file.loadFromFile GetFolderItem(fileFld.text)
mail.attachments.append file
end
// send the email
socket1.messages.append mail
progressBar1.visible = True
socket1.sendMail
The Action event of a PushButton connects to a POP3 server and gets the email for the specified account. It reads the POP3Server, username, and password from EditFields on the form. Socket1 is a POP3Socket object.
socket1.address =serverFld.text
socket1.port =110
socket1.username = usernameFld.text
socket1.password = passwordFld.text
socket1.connect
Me.caption = "Disconnect"
else
socket1.disconnectFromServer
Me.caption = "Connect"
end if
The MessageReceived event of the POP3Socket places the text of the message in the EditField, bodyFld.
// display the message
s = email.bodyHTML
if s = "" then
s = email.bodyPlainText
end
bodyFld.text = ReplaceAll(s,chr(13)+chr(10),chr(13))
See also the examples for the SMTPSocket and POP3Socket classes.
See Also
EmailAttachment, EmailHeaders, HTTPSecureSocket, HTTPSocket, POP3SecureSocket, POP3Socket, SMTPSecureSocket, SMTPSocket, SocketCore, SSLSocket, TCPSocket classes.